package com.itguigu.controller;

import com.itguigu.pojo.Headline;
import com.itguigu.service.HeadlineService;
import com.itguigu.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("headline")
public class HeadLineController {

    @Autowired
    private HeadlineService headlineService;


    @PostMapping("publish")
    public Result publish(@RequestHeader String token, @RequestBody Headline headline){


        Result result = headlineService.publish(headline,token);

        return result;

    }




    @PostMapping("findHeadLineByHid")
    public Result findHeadLineByHid(Integer hid){

        Headline headline = headlineService.getById(hid);

        HashMap<Object, Object> data = new HashMap<>();
        data.put("headline",headline);
        return Result.ok(data);

    }



    @PostMapping("update")
    public Result update(@RequestBody Headline headline){


        Result result = headlineService.updateDate(headline);
        return result;

    }


    @PostMapping("removeByHid")
    public Result removeByhId(Integer hid){

        headlineService.removeById(hid);
        return Result.ok(null);
    }




}
